package com.example.mapper;

import com.example.annotation.AutoFill;
import com.example.dto.EmployeeDTO;
import com.example.entity.Employee;
import com.example.enumeration.OperationType;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EmployeeMapper {

     /**
     * 用户登陆
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    EmployeeDTO getByUsername(String username);

    /**
     * 展示所有员工
     * @return
     */
    @Select("select * from employee")
    Page<EmployeeDTO> showEmployee(Integer size,Integer pageSize);

    /**
     * 根据id删除员工
     * @param id
     */
    @Delete("delete from employee where id=#{id}")
    void deleteEmployee(Integer id);

    /**
     * 新增员工
     * @param employee
     */
    @Insert("insert into employee (name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user,status) " +
            "values " +
            "(#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})")
    @AutoFill(value =OperationType.INSERT)
    void addEmployee(Employee employee);


    /**
     * 查询员工并且分页展示
     * @param name
     * @param page
     * @param pageSize
     * @return
     */
    Page<EmployeeDTO> selectEmployee(String name, Integer page, Integer pageSize);


    /**
     * 根据id更改员工状态 1为启用 0为禁用
     * @param status
     * @param id
     */
    @Update("update employee set status=#{status}  where id=#{id}")
    void starOrStop(Integer status, Integer id);

    /**
     * 数据回显
     * @param id
     * @return
     */
    @Select("select * from employee where id=#{id}")
    EmployeeDTO getById(Integer id);

    /**
     * 修改员工
     * @param employeeDTO
     */
    @AutoFill(value = OperationType.UPDATE)
    void updateEmployee(EmployeeDTO employeeDTO);

    /**
     * 修改密码
     * @param id
     * @param pwd
     */
    @Update("update  employee set password=#{pwd} where id=#{id}")
    void changePassWord(String pwd,Integer id);

    /**
     * 批量删除
     * @param ids
     */
    void deleteEmps(List<Integer> ids);
}
